import numpy as np
import tensorflow as tf
import numpy

# 测试精确度指标
m = tf.keras.metrics.Accuracy()
m.update_state(y_true=[[1], [2], [3], [4]], y_pred=[[1], [1], [3], [4]], sample_weight=[1, 1, 0, 0])
print(f'total={m.total},count={m.count}')
print(m.result())

# 测试归一化函数 softmax
activation_input = tf.random.normal([2, 4], 0, 1)
activation_output = tf.keras.activations.softmax(activation_input)
print(f'input={activation_input},output={activation_output}')

# 取数组（多维）中最大值所在的索引位置
print(numpy.argmax(activation_output))

nparray = numpy.array([[10, 11, 12],
                       [13, 14, 15]])
print(nparray.shape)
print(numpy.argmax(nparray))
print(numpy.argmax(nparray, 1))

arr1 = numpy.array([1, 2, 3])
arr2 = numpy.array([1, 1, 3])
matches = arr1 == arr2
print(f'accuracy={matches.mean():.2f}')

# 测试张量的逐元素运算
nparray = nparray.astype(dtype='float32')
nparray -= np.mean(nparray, axis=0)
print(np.mean(nparray, axis=0))
